package com.shujia;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.resps.Tuple;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class RedisAPI {
    public static void main(String[] args) {
        //创建与redis的连接对象
        Jedis jedis = new Jedis("192.168.11.100", 7000);
//        jedis.select(0);
//        //测试key相关操作
//        jedis.set("name","shangping");
//        jedis.set("age","18");
//        jedis.set("address","hefei");
//
//        boolean name = jedis.exists("name");
//        System.out.println(name);
//        long name = jedis.expire("name", 500);
//        //list数据类型的值
//        jedis.lpush("list","hadoop","hbase","redis");
//        jedis.lpush("date","12","13","14");
//        List<String> list = jedis.lrange("list", 0, -1);
//        for (String s : list) {
//            System.out.println(s);
//        }
        //操作set 类型的值
//       jedis.sadd("name1","xiaohu1","xiaohu2","xiaohu3");

//        Set<String> name1 = jedis.smembers("name1");
//        for (String s : name1) {
//            System.out.println(s);
//        }

//        jedis.sadd("shangping","pingguo","juzhi","xiangjiao","lizhi","lizhi");
//        Set<String> shangping = jedis.smembers("shangping");
//        for (String s : shangping) {
//            System.out.println(s);
//        }
////
//
//        HashMap<String, Double> map = new HashMap<>();
//        map.put("xiaohu",80.0);
//        map.put("xiaohu1",82.0);
//        map.put("xiaohu2",84.0);
//        jedis.zadd("score",map);
//        //升序获取
//        List<Tuple> score = jedis.zrangeWithScores("score", 0, 100);
//        for (Tuple tuple : score) {
//            String element = tuple.getElement();
//            double score1 = tuple.getScore();
//            System.out.println(score1+"=="+element);
//            //降序获取
//            List<Tuple> score2 = jedis.zrevrangeWithScores("score", 0, 100);
//            for (Tuple score3 : score2) {
//                String element1 = score3.getElement();
//                double score4 = score3.getScore();
//                System.out.println(score4+":"+element1);
//            }
//            //操作hash类型数据的值
//            //先将值的map集合封装一下
//            HashMap<String, String> map1 = new HashMap<>();
//            map1.put("姓名","小虎");
//            map1.put("年龄","18");
//            map1.put("地址","安徽");
//            jedis.hset("小虎info",map1);

        Map<String, String> info = jedis.hgetAll("小虎info");
        Set<Map.Entry<String, String>> entries = info.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println(value+":"+key);
        }
        jedis.setbit("bitmap",1,true);
        jedis.setbit("bitmap",7,true);
        jedis.close();

    }

    }

